home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / FGMISC10.ZIP / COMMON.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-26  |  3.7 KB  |  107 lines

  1. /****************************************************************************\
  2. *                                                                            *
  3. *  common.c -- functions we use a lot, such as video mode initialization     *
  4. *  and termination, random number generator, etc.                            *
  5. *                                                                            *
  6. \****************************************************************************/
  7.  
  8. #define common_c
  9. #include "defs.h"
  10.  
  11. /****************************************************************************\
  12. *                                                                            *
  13. *  file_exists -- is the file on the disk?                                   *                                       *
  14. *                                                                            *
  15. \****************************************************************************/
  16.  
  17. int file_exists(char *filename)
  18. {
  19.    if (access(filename,0) == 0)
  20.       return(TRUE);
  21.    else
  22.       return(FALSE);
  23. }
  24.  
  25. /****************************************************************************\
  26. *                                                                            *
  27. *  flushkey -- flush out the keystroke buffer                                *
  28. *                                                                            *
  29. \****************************************************************************/
  30.  
  31. void flushkey()
  32. {
  33.    unsigned char key,aux;
  34.  
  35.    fg_intkey(&key,&aux);
  36.    while (key+aux > 0) fg_intkey(&key,&aux);
  37. }
  38.  
  39. /****************************************************************************\
  40. *                                                                            *
  41. *      init_graphics -- initialize the graphics environment                  *
  42. *                                                                            *
  43. \****************************************************************************/
  44.  
  45. void init_graphics(int mode)
  46. {
  47.    /* initialize Fastgraph for the specified video mode */
  48.  
  49.    if (fg_testmode(mode,2) == 0)
  50.    {
  51.       printf("Required video mode not available on this system.\n");
  52.       exit(1);
  53.    }
  54.    old_mode = fg_getmode();
  55.    fg_setmode(mode);
  56.  
  57.    /* set up visual and hidden pages */
  58.  
  59.    fg_setpage(VISUAL);
  60.    fg_setvpage(VISUAL);
  61.    fg_sethpage(HIDDEN);
  62.  
  63.    clockspeed = fg_measure();
  64.    stall_time = 0;
  65.  
  66.    white= 15; red = 12; grey = 8; black = 0; blue = 9; dkblue = 1;
  67. }
  68.  
  69. /****************************************************************************\
  70. *                                                                            *
  71. *  init_mouse -- initialize the mouse if present                             *
  72. *                                                                            *
  73. \****************************************************************************/
  74.  
  75. init_mouse()
  76. {
  77.    if (fg_mouseini() > 0)
  78.    {
  79.       mouse = TRUE;
  80.       xmouse = (fg_getmaxx()+1)/2;
  81.       ymouse = (fg_getmaxy()+1)/2;
  82.       fg_mousemov(xmouse,ymouse);
  83.       fg_mousevis(ON);
  84.       return(TRUE);
  85.    }
  86.    else
  87.    {
  88.       mouse = FALSE;
  89.       return(FALSE);
  90.    }
  91. }
  92.  
  93. /****************************************************************************\
  94. *                                                                            *
  95. *  quit_graphics -- return the computer to its original state                *
  96. *                                                                            *
  97. \****************************************************************************/
  98.  
  99. void quit_graphics()
  100. {
  101.    fg_mousefin();
  102.    fg_setmode(old_mode);
  103.    fg_reset();
  104.  
  105.    exit(0);
  106. }
  107.